package com.cqw.order.domain;

import com.cqw.order.enums.ItemStateEnum;
import com.cqw.vo.order.ItemReq;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

@Data
@NoArgsConstructor
public class Item {
    @ApiModelProperty(value = "id")
    private Long id;

    @ApiModelProperty(value = "shopId店铺id")
    private Long shopId;

    @ApiModelProperty(value = "parentId父id")
    private Long parentId;

    @ApiModelProperty(value = "seq排序")
    private Integer seq;

    @ApiModelProperty(value = "itemName分类名称")
    private String itemName;

    @ApiModelProperty(value = "itemPic分类图片")
    private String itemPic;

    @ApiModelProperty(value = "itemIcon分类图标")
    private String itemIcon;

    @ApiModelProperty(value = "state默认1,1是正常状态，0是下线状态")
    private ItemStateEnum state;

    @ApiModelProperty(value = "grade分类层级")
    private Integer grade;

    @ApiModelProperty(value = "createTime创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "updateTime修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    private List<Item> child;


    public Item(ItemReq itemReq) {
        this.id = itemReq.getId();
        this.shopId = itemReq.getShopId();
        this.parentId = itemReq.getParentId();
        this.seq = itemReq.getSeq();
        this.itemName = itemReq.getItemName();
        this.itemPic = itemReq.getItemPic();
        this.itemIcon = itemReq.getItemIcon();
        this.state = itemReq.getState() == null ? ItemStateEnum.ON_LINE : itemReq.getState();
        this.grade = itemReq.getGrade();
        this.createTime = itemReq.getCreateTime() == null ? new Date() : itemReq.getCreateTime();
        this.updateTime = new Date();
    }

}